package com.sunxueqi.project.log.service.impl;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.sunxueqi.common.constant.StatusConstants;
import com.sunxueqi.common.utils.SecurityUtils;
import com.sunxueqi.project.log.dao.OperationLogMapper;
import com.sunxueqi.project.log.service.IOperationLogService;
import com.sunxueqi.project.log.vo.OperationLog;

@Service
public class OperationLogServiceImpl implements IOperationLogService{

	@Autowired
	private OperationLogMapper operationLogMapper;
	
	@Override
	public List<OperationLog> selectOperationLogList(OperationLog operationLog) {
		operationLog.setDeleteStatus(StatusConstants.NORMAL);
		return operationLogMapper.selectList(operationLog);
	}

	@Override
	public int deleteOperationLogByIds(String[] idArray) {
		int result = 0;
		for(String id: idArray) {
			OperationLog OperationLog = new OperationLog();
			OperationLog.setId(id);
			OperationLog.setDeleteStatus(StatusConstants.DELETED);
			OperationLog.setDeleteTime(new Timestamp(System.currentTimeMillis()));
			OperationLog.setDeleteBy(SecurityUtils.getLoginUserId());
			int count = operationLogMapper.updateByPrimaryKey(OperationLog);
			result += count;
		}
		return result;
	}
	
	@Override
	public void cleanLog() {
		operationLogMapper.cleanLog(SecurityUtils.getLoginUserId(), StatusConstants.DELETED, StatusConstants.NORMAL);
	}

	@Override
	public int insertOperationLog(OperationLog operationLog) {
		return operationLogMapper.insert(operationLog);
	}
}
